package com.pm.web.controller.projectManage;


import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.core.page.TableDataInfo;
import com.pm.common.enums.BusinessType;
import com.pm.common.core.domain.entity.ProjectTempleteDefine;
import com.pm.common.core.domain.entity.ProjectTempleteVersion;
import com.pm.project.domain.vo.ProjectTempleteVersionVO;
import com.pm.project.service.ProjectTempleteService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 项目模板管理
 */
@RestController
@RequestMapping("/project/templete")
public class ProjectTempleteController extends BaseController {

    @Resource
    private ProjectTempleteService projectTempleteService;

    @Log(title = "项目模板:预新增",businessType = BusinessType.INSERT)
    @PostMapping("/prepare/add")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:add')")
    public AjaxResult prepareAdd(@RequestBody ProjectTempleteVersion projectTempleteVersion){
        return projectTempleteService.prepareAdd(projectTempleteVersion);
    }


    @Log(title = "项目模板:新增模版",businessType = BusinessType.INSERT)
    @PostMapping("add")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:add')")
    public AjaxResult add(@RequestBody ProjectTempleteVersion projectTempleteVersion){
        return projectTempleteService.add(projectTempleteVersion);
    }


    @Log(title = "项目模板:复制模版",businessType = BusinessType.INSERT)
    @PostMapping("copy")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:add')")
    public AjaxResult copy(@RequestBody ProjectTempleteVersion projectTempleteVersion){
        return projectTempleteService.copy(projectTempleteVersion);
    }


    @Log(title = "项目模板:设置成当前版本",businessType = BusinessType.UPDATE)
    @GetMapping("updateStatus")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:set')")
    public AjaxResult updateStatus(String id){
        return projectTempleteService.updateStatus(id);
    }


    @Log(title = "项目模板:添加节点",businessType = BusinessType.INSERT)
    @PostMapping("/add/node")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:add')")
    public AjaxResult addNode(@RequestBody ProjectTempleteDefine projectTempleteDefine){
        return projectTempleteService.addNode(projectTempleteDefine);
    }


    @Log(title = "项目模板:修改节点",businessType = BusinessType.UPDATE)
    @PostMapping("/update/node")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:update')")
    public AjaxResult updateNode(@RequestBody ProjectTempleteDefine projectTempleteDefine){
        return projectTempleteService.updateNode(projectTempleteDefine);
    }

    @Log(title = "项目模板:删除节点",businessType = BusinessType.DELETE)
    @PostMapping("/del/node")
    @PreAuthorize("@ss.hasPermi('projectManage:templete:delete')")
    public AjaxResult delNode(@RequestBody ProjectTempleteDefine projectTempleteDefine){
        return projectTempleteService.delNode(projectTempleteDefine);
    }


    @GetMapping("/list")
    @Log(title = "项目模板:查询模版列表",businessType = BusinessType.OTHER)
    public TableDataInfo list(ProjectTempleteVersion projectTempleteVersion)
    {
        startPage();
        List<ProjectTempleteVersionVO> list = projectTempleteService.list(projectTempleteVersion);
        return getDataTable(list);
    }


    @GetMapping("/detail")
    @Log(title = "项目模板:查询模板详情",businessType = BusinessType.OTHER)
    public AjaxResult detail(ProjectTempleteVersion projectTempleteVersion)
    {
        ProjectTempleteVersion res = projectTempleteService.detail(projectTempleteVersion);
        return AjaxResult.success(res);
    }

    @GetMapping("/curr/temDetail")
    @Log(title = "项目模板:查询当前模板详情",businessType = BusinessType.OTHER)
    public AjaxResult currTemDetail(ProjectTempleteVersion projectTempleteVersion)
    {
        ProjectTempleteVersion res = projectTempleteService.currTemDetail(projectTempleteVersion);
        return AjaxResult.success(res);
    }


}

